package com.fbt.andon.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fbt.andon.domain.Task;
import com.fbt.andon.service.impl.TaskServiceImpl;

import com.linkwechat.common.core.controller.BaseController;
import com.linkwechat.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 计划产量Controller
 *
 * @author fengtao
 * @date 2021-08-14
 */
@RestController
@RequestMapping("/task")
@Api(description = "计划产量api")
public class TaskController extends BaseController {
    @Autowired
    private TaskServiceImpl taskService;


    //@PreAuthorize(hasPermi = "mes:andon:query")
    @GetMapping(value = "/list")
    @ApiOperation("查询该表所有信息")
    public AjaxResult findUserList() {
        startPage();
        return AjaxResult.success("查询成功", taskService.list(null));
    }


    /**
     * 查询计划产量列表
     */
    //@PreAuthorize(hasPermi = "andon:task:list")
    @GetMapping("/list/{workName}")
    @ApiOperation("根据工作岗位模糊查询")
    public AjaxResult list(String workName) {
        startPage();
        QueryWrapper<Task> wrapper = new QueryWrapper<>();
        wrapper.like("work_name", workName);
        return AjaxResult.success("查询成功", taskService.list(wrapper));
    }


    /**
     * 获取计划产量详细信息
     */
    //@PreAuthorize(hasPermi = "andon:task:query")
    @ApiOperation("获取计划产量详细信息，参数pkId")
    @GetMapping("/get/{pkId}")
    public AjaxResult getInfo(@PathVariable("pkId") Integer pkId) {
        return AjaxResult.success("查询成功", taskService.getById(pkId));
    }


    /**
     * 新增计划产量
     */
    //@PreAuthorize(hasPermi = "andon:task:add")
    @ApiOperation("新增计划产量，参数task")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Task task) {
        return AjaxResult.success("新增成功", taskService.save(task));
    }

    /**
     * 修改计划产量
     */
    //@PreAuthorize(hasPermi = "andon:task:edit")
    @ApiOperation("根据id修改计划产量，参数task")
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody Task task) {
        return AjaxResult.success("修改成功", taskService.updateById(task));
    }

    /**
     * 删除计划产量
     */
    //@PreAuthorize(hasPermi = "andon:task:remove")
    @ApiOperation("删除计划产量，参数pkIds")
    @PostMapping("/deletes/{pkIds}")
    public AjaxResult remove(@PathVariable Long[] pkIds) {
        return AjaxResult.success("修改成功", taskService.listByIds(Arrays.asList(pkIds)));
    }
}
